package com.wang.auth.controller;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.wang.auth.service.SysOperLogService;
import com.wang.common.result.Result;
import com.wang.model.system.SysOperLog;
import com.wang.model.system.vo.SysLoginLogVo;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 操作日志记录 前端控制器
 * </p>
 *
 * @author wang
 * @since 2023-04-17
 */
@RestController
@RequestMapping("/admin/system/sysOperLog")
public class SysOperLogController {

    @Autowired
    SysOperLogService operLogService;

    @GetMapping("/{page}/{limit}")
    @PreAuthorize("hasAuthority('bnt.sysUser.list')")
    public Result index(@PathVariable Long page, @PathVariable Long limit, SysLoginLogVo sysLoginLogVo){
        Page<SysOperLog> sysOperLogPage = new Page<>(page, limit);
        LambdaQueryWrapper<SysOperLog> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        String keyword = sysLoginLogVo.getKeyword();
        lambdaQueryWrapper.eq(StringUtils.isNotBlank(keyword),SysOperLog::getOperName,keyword);
        lambdaQueryWrapper.ge(sysLoginLogVo.getCreateTimeBegin() != null,SysOperLog::getCreateTime,sysLoginLogVo.getCreateTimeBegin());
        lambdaQueryWrapper.le(sysLoginLogVo.getCreateTimeEnd() != null,SysOperLog::getCreateTime,sysLoginLogVo.getCreateTimeEnd());
        lambdaQueryWrapper.orderByDesc(SysOperLog::getOperTime);
        return Result.success(operLogService.page(sysOperLogPage,lambdaQueryWrapper));

    }
}
